<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Proxy日志记录</title>
</head>
<body>
<script>
    function makeLoggable(target) {  // 使得target可以记录日志
        return new Proxy(target, {
            get(target, p) {
                console.log('reading '+p);
                return target[p];
            },
            set(target, p, value) {
                console.log('writing '+p);
                target[p] = value
            }
        })
    }

    let ninja = {name: 'Samuel'};
    ninja = makeLoggable(ninja);
    console.log(ninja.name);
    ninja.nickName = 'Zhangboy';
</script>
</body>
</html>
